<#assign nojs=true>
<#include "/WEB-INF/default/fragment/header.ftl">
<body>

<script type="text/javascript" src="${request.contextPath}/assets/js/jquery.js"></script>
<script src="//cdn.bootcss.com/moment.js/2.10.6/moment.min.js"></script>
<script src="//cdn.bootcss.com/moment.js/2.18.1/locale/zh-cn.js"></script>
<script type="text/javascript" src="${request.contextPath}/assets/js/bootstrap.min.js"></script>

<#include "/WEB-INF/default/fragment/nav.ftl">

<link href="//cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker-standalone.min.css" rel="stylesheet">
<link href="//cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="//cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>

<style>
.legend {
  border-bottom: 1px solid red;
  padding: 0px;
}
fieldset {
  width: 80%;
  margin: 0 auto;
}
</style>
<div class="container">
  <div class="tms-logo"><img class="center-block" src="${request.contextPath}/assets/images/logo.png?t=${assetsTimestamp}" alt=""></div>
</div>

<div class="container">
<form class="form-horizontal" action="${request.contextPath}/task-commit.action?task.id=${task.id}" method="post">
  <legend class="clearfix">
    <div class="pull-left"><h4>${title!"任务明细"}</h4></div>
    <div class="pull-right">
      <a href="${request.contextPath}/team-${team.id}.action" class="btn btn-default">团队首页</a>
      <#if (privilege == 2)>
      <button type="submit" class="btn btn-success">提交任务</button>
      <#elseif (privilege == 0)>
      <a href="${request.contextPath}/login-index.action?redirectUrl=" class="btn btn-success">登录提交任务</a>
      </#if>
    </div>
  </legend>
  <fieldset>
    <#if (privilege != 2)>
    <div class="alert alert-warning alert-dismissible" role="alert">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <strong>注意</strong> 只有${team.name}的成员才能提交任务
    </div>
    </#if>

    <div class="form-group">
      <label class="col-sm-2 control-label">所属项目</label>
      <div class="col-sm-10">
        <p class="help-block"> ${task.project.title?html}</p>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-2 control-label">任务名称</label>
      <div class="col-sm-10">
        <p class="help-block">${task.title?html}</p>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-2 control-label">任务描述</label>
      <div class="col-sm-10">
        <p class="help-block"><pre>${task.desc?html}</pre></p>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-2 control-label">开始时间</label>
      <div class="col-sm-10">
        <p class="help-block">${gmtStart?date?string("yyyy-MM-dd hh:mm:ss")}</p>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-2 control-label">截止时间</label>
      <div class="col-sm-10">
        <p class="help-block">${gmtFinished?date?string("yyyy-MM-dd hh:mm:ss")}（<#if gmtLeft lt 0>已结束<#else>剩余 <time>${gmtLeft}</time>小时</#if>）</p>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-2 control-label">参考附件：</label>
      <div class="col-sm-10">
        <p class="help-block"><a href="${task.attachmentUrl?html}">${task.attachmentUrl?html}</a></p>
      </div>
    </div>

    <#if (privilege == 2)>
    <div class="form-group">
      <label class="col-sm-2 control-label">附件：</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" name="userTask.attachmentUrl" id="startDate" value="<#if userTask?exists && userTask.attachmentUrl?exists>${userTask.attachmentUrl?html}</#if>">
        <a class="btn btn-link j_upload_box" data-toggle="modal" data-target="#tmsUploadModal">上传附件</a>
        <p class="help-block">提交符合任务要求的附件，可能要包含源码截图和运行结果截图，如果是多个文件，请压缩成 zip 格式。</p>
        <#if fieldErrors?exists && fieldErrors['userTask.attachmentUrl']?exists>
        <p class="help-block"><span class="text-danger">${fieldErrors['userTask.attachmentUrl']}</span></p>
        </#if>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">备注</label>
      <div class="col-sm-10">
        <textarea class="form-control" name="userTask.remark"><#if userTask?exists && userTask.remark?exists>${userTask.remark?html}</#if></textarea>
        <p class="help-block">完成任务的补充描述，如：请按照附件要求或者参考附件效果</p>
        <#if fieldErrors?exists && fieldErrors['userTask.remark']?exists>
        <p class="help-block"><span class="text-danger">${fieldErrors['userTask.remark']}</span></p>
        </#if>
      </div>
    </div>
    <#elseif (privilege == 0)>
    </#if>

    <div class="form-group">
      <label class="col-sm-2 control-label">任务提交情况：</label>
      <div class="col-sm-10">
        <table class="table" style="padding-top: 7px;">
          <thead>
            <tr>
              <td>成员</td>
              <td>任务附件</td>
              <td>提交状态</td>
              <td>操作</td>
            </tr>
          </thead>
          <tbody>
            <#list userTasks as t>
            <tr> <#-- ${t.gmtModified?date?string("yyyy-MM-dd hh:mm:ss")} -->
              <td><a href="${request.contextPath}/user-${t.user.id}.action">${t.user.nickname}</a></td>
              <td><a href="${t.attachmentUrl}">${t.attachmentUrl}</a></td>
              <#if t.status == 0>
              <td>尚未提交任务</td>
              <#elseif t.status == 1>
              <td>已提交</td>
              <#elseif t.status == 2>
              <td>任务已完成</td>
              </#if>
              <td class="btn-group-xs">
                <#if t.status == 1>
                <a class="btn btn-success btn-xs j_finish_task" href="" data-user-task-id="${t.id}" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> 正在确认">确认任务</a>
                </#if>
                <#if t.status == 2>
                <span class="text-info">任务已确认</span>
                </#if>
              </td>
            </tr>
            </#list>
          </tbody>
        </table>
      </div>
    </div>


  </fieldset>
</form>
</div>

<script src="${request.contextPath}/assets/js/app.js?t=${assetsTimestamp}"></script>

<script>
var onUploadSucced = function(url) {
  $('input[name="userTask.attachmentUrl"]').val(url);
}
</script>
<#include "/WEB-INF/default/fragment/upload.ftl">

</body>
<#include "/WEB-INF/default/fragment/footer.ftl">
